Re: [GENERAL] Still the problem with the autoincrement field

Поиск
Список
Период
Сортировка
От Herouth Maoz
Тема Re: [GENERAL] Still the problem with the autoincrement field
Дата
Msg-id l03110701b23f9a2c84c3@[147.233.159.109]
обсуждение исходный текст
Список pgsql-sql
At 11:29 +0200 on 6/10/98, Marc Eggenberger wrote:


> when I do the following:
>
> insert into offene_stellen values ('', 'Maurer', 'Buchs', 'Rheinhalter
>Claudio', 'flexibilitaet', 'gutes Team');
>
> the id field is always 0, and when I do a:
>
> insert into offene_stellen values ('Maurer', 'Buchs', 'Rheinhalter
>Claudio', 'flexibilitaet', 'gutes Team');
>
> I get a:
> ERROR:  pg_atoi: error in "Maurer": can't parse "Maurer"
>
>
> How do I add data, so that the id field is autoincremented?

Simple. NEVER do an insert without mentioning the field names. It is never
advisable to rely on the order of the fields in the database, in any case.
In this case, you simply must not enter a value to the field, so that in
knows that it should insert the default value.

So, what you should do is:

INSERT INTO offene_stellen (
    bezeichnung,
    arbeitsort,
    berater
    gefordert
    geboten
)
VALUES (
    'Maurer',
    'Buchs',
    'Rheinhalter Claudio',
    'flexibilitaet',
    'gutes Team'
);

This works, and it also makes sure that if you change the schema such that
the order of the fields is different or there are new fields between the
existing fields, the query won't break.

But if you insist on not mentioning field names, I think inserting a NULL
rather than a value in the id field should work. I won't swear on it, but I
think you should make that field NOT NULL in the table definition.

Remember that '' (The empty string) is NOT THE SAME THING as a NULL. The
empty string is just a string with length 0. NULL is "There is nothing
here".

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



В списке pgsql-sql по дате отправления:

Предыдущее
От: Herouth Maoz
Дата:
Сообщение: RE: [SQL] Getting datatype before SELECT
Следующее
От: "James Oden"
Дата:
Сообщение: Re: [SQL] Re: [GENERAL] Still the problem with the autoincrement field